<?php
/**
 * Ecma-262 5rd 7.6
 * 
 */
class IdentifierName extends Token{
    
    const NotReservedWord = 0;
    const IsReservedWord = 1;
    
    /**
     * 
     * @var int
     */
    public $idType;
    
    /**
     * @return the $idType
     */
    public function getIdType() {
        return $this->idType;
    }
    
    /**
     * @param int $idType
     */
    public function setIdType($idType) {
        $this->idType = $idType;
    }
    
    public function __construct(){
        parent::__construct ();
        $this->tokenType = Token::IdentifierName;
        $this->idType = IdentifierName::NotReservedWord;
    }
    
    /**
     * Ecma-262 5rd 7.6
     * 
     * 暂时不支持Unicode
     */
    public static function isIdentifierStart($char){
        if(preg_match('/[a-zA-Z]/', $char) ){
            return true;
        }
        
        if($char == '$'){
            return true;
        }
        
        if($char == '_'){
            return true;
        }
        
        return false;
    }
    
    /**
     * Ecma-262 5rd 7.6
     * 
     * 暂时不支持Unicode
     */
    public static function isIdentifierPart($char){
        if(self::isIdentifierStart($char)){
            return true;
        }
        
        if(preg_match('/[0-9]/', $char) ){
            return true;
        }
        
        return false;
    }
}